package hqu.cst.XAH.mapper;

import hqu.cst.XAH.pojo.Movie;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MovieMapper {
    @Select("SELECT * FROM movies")
    List<Movie> getAllMovies();

    @Select("SELECT * FROM movies WHERE id = #{id}")
    Movie getMovieById(Long id);


    @Insert("INSERT INTO movies (title, director, description, poster_url) VALUES (#{title}, #{director}, #{description}, #{posterUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertMovie(Movie movie);

    @Delete("DELETE FROM movies WHERE id = #{id}")
    void deleteMovieById(Long id);

    @Update("UPDATE movies SET title = #{title}, director = #{director}, description = #{description}, poster_url = #{posterUrl} WHERE id = #{id}")
    void updateMovie(Movie movie);
}
